<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\controller;

use app\validate\MsgPushValidate;
use app\service\MediaAnalyzeService;
use app\service\PushService;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\exception\ApiException;
use support\Log;
use support\Request;
use support\Response;

/**
 * 团队表控制器
 */
class ToolController extends BaseController
{

    //去水印
    public function watermarkWipe(Request $request, MediaAnalyzeService $toolService): Response
    {
        $mediaUrl = $request->input('media_url');
        if (!$mediaUrl) {
            throw new ApiException('链接不能为空');
        }
        preg_match('/https:\/\/[A-Za-z0-9_.\/]+(\s?)/', $mediaUrl, $mediaUrlArr);
        if (count($mediaUrlArr) == 0) {
            throw new ApiException('参数错误,请输入正确的链接');
        }
        $mediaResult = $toolService->analyze($mediaUrlArr[0]);
//        $mediaResult = [
//            'https://p3-pc-sign.douyinpic.com/tos-cn-i-0813/oYpISDT4ADfmhCQ18iFEg0QE9A1GAThfAACmAv~tplv-dy-aweme-images-v2:3000:3000:q75.webp?x-expires=1724983200&x-signature=gcZG5FSilqBKirhMPEt5mn7DgKc%3D&from=327834062&s=PackSourceEnum_AWEME_DETAIL&se=false&sc=image&biz_tag=aweme_images&l=20240731105939863F527EBD7D53444B42',
//            'https://p3-pc-sign.douyinpic.com/tos-cn-i-0813/oYAh6hIgCGAFkEvfEE9T1mf4A0DrACAQQASmp1~tplv-dy-aweme-images-v2:3000:3000:q75.webp?x-expires=1724983200&x-signature=CBEnmpf3xX2cnqpr9Y%2FOv3N5c8M%3D&from=327834062&s=PackSourceEnum_AWEME_DETAIL&se=false&sc=image&biz_tag=aweme_images&l=20240731105939863F527EBD7D53444B42'
//        ];
        return $this->success(['media_source_url'=>$mediaResult],'解析成功');
    }

    //企业消息推送
    public function msgPush(Request $request,MsgPushValidate $validate,PushService $service)
    {
        $check = $validate->check($request->post());
        if(!$check){
            return $this->fail($validate->getError());
        }
        $result = $service->push($request->post());
        return $this->success($result,'推送消息成功');
    }
}
